<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>


        // ajax 请求的时候，， 跨域或者路径错误   try catch  捕获不到




        const p = new Promise(function(resolve , reject){
            // 异步的程序
            const xhr = new XMLHttpRequest() ;
            console.log(xhr.readyState);
            xhr.open('get' , '../php/1.php' , true) ;
            console.log(xhr.readyState);
            xhr.send() ;
            xhr.onreadystatechange = function() {
                // console.log(xhr.readyState);   // 2 3 4
                if(xhr.readyState === 4 && xhr.status === 200) {
                    // resolve('成功啦') ;
                    let data = xhr.responseText ;
                    resolve(data) ;
                } else {
                    reject('错误');
                }
            }

        })


        p.then(
            function(data) {
                console.log(data);
            } ,
            function(err) {
                console.log(err);
            }
        )

    </script>
    
</body>
</html>